import { defineStore } from 'pinia';
import type { User } from '@/types/user'
import { ref } from 'vue';

export const useUserStore = defineStore('cp-user', () => {
  // 用户信息
  const user = ref<User>();
  const token = ref<string>();

  // 设置用户信息
  const setUser = (userInfo: User) => {
    user.value = userInfo;
  };

  // 设置token
  const setToken = (tok: string) => {
    token.value = tok;
  };

  // 退出登录
  const logout = () => {
    user.value = undefined;
  };

  return {
    user,
    setUser,
    logout,
    setToken,
    token
  }

}, {
  persist: true
});
